package cn.com.acca.ma.dao.impl;

import cn.com.acca.ma.dao.UserTableColumnDao;
import cn.com.acca.ma.hibernate.util.HibernateUtil;
import cn.com.acca.ma.model.db.UserTableColumns;
import org.hibernate.Query;

import java.util.ArrayList;
import java.util.List;

public class UserTableColumnDaoImpl extends BaseDaoImpl<UserTableColumnDaoImpl> implements UserTableColumnDao {

    public UserTableColumnDaoImpl() {
        super();
    }

    /**
     * 根据table_name字段查找记录
     * @param tableName
     * @return
     */
    @Override
    public List<UserTableColumns> findByTableName(String tableName) {
        List<UserTableColumns> list = new ArrayList<UserTableColumns>();
        session = HibernateUtil.currentSession();
        session.beginTransaction();
        Query query = session.createQuery("SELECT t FROM UserTableColumns t where t.key.tableName=:tableName order by t.columnId asc");
        query.setString("tableName", tableName);
        list = query.list();
        session.getTransaction().commit();
        session.close();
        return list;
    }
}
